class MyClass:
"""
Brief summary of purpose and behaviour
...
Attributes
----------
attribute1 : str
an attribute
attribute2 : str
another attribute
Methods
-------
a_method
Prints attribute2
"""
attribute1 = "asdf"
def __init_(self, attribute2: str):
"""
Parameters
----------
attribute2 : str
another attribute
Raises
------
NotImplementedError
If no sound is set for the animal or passed in as a
parameter.
"""
self.attribute2 = attribute2
def a_method(self):
"""Prints attribute2"""
print(self.attribute1)__init__.py filehello.py
"""One-line summary of what the script does
Blah
Blah
This file can also be imported as a module and contains the following
functions:
* hello - prints hello (name}
* main - the main function of the script
"""
import sys
def hello(name):
"""Prints hello (name}
Parameters
----------
name : str
The name to print
"""
print("hello", name)
def main():
hello(sys.argv[1])
if __name__ == "__main__":
main()python hello.py you
# hello youThis bit doesn’t work…
python hello.py -h
# hello -hargparse you can omit parameter-specific documentation
argparser.parser.add_argument function__doc__ for the description parameter within argparse.ArgumentParser constructor.
Comments
Limit line length for comments and docstrings to 72 characters (https://pep8.org/#maximum-line-length)
tags
type hints
docstring basics
Always use triple double quote string format, even if it’s just one line.
The built-in function
help()prints out the objects docstring to the console.